#define _GNU_SOURCE         /* See feature_test_macros(7) */
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>



#define LOG(fmt,...) printf("[%s:%d]"fmt,__FILE__,__LINE__,##__VA_ARGS__);


void printfNum(int count,...)
{
    va_list ap;
    va_start(ap,count); // 获取count之后第一个不定参的位置
    for(int i = 0; i<count; i++)
    {
        int num = va_arg(ap,int);
        printf("param[%d]:%d\n",i,num);
    }

    va_end(ap); // 将ap指针置空
}

void myprintf(const char* fmt,...)
{
    va_list ap;
    va_start(ap,fmt);
    char* res;
    int ret = vasprintf(&res,fmt,ap);
    if(ret != -1)
    {
        printf(res);
        free(res);
    }

    va_end(ap); 
}

int main()
{
    LOG("hello world\n");
    printfNum(3,666,7777,888);  
    printfNum(5,1,2,3,4,5);
    myprintf("%s:%d\n","hello world",666);

    return 0;
}
